import 'package:fish_redux/fish_redux.dart';

import 'action.dart';
import 'state.dart';

Reducer<WebState> buildReducer() {
  return asReducer(
    <Object, Reducer<WebState>>{
      WebAction.onTitle: _onTitle,
      WebAction.countUp: _countUp,
    },
  );
}

WebState _onTitle(WebState state, Action action) {
  final WebState newState = state.clone()..progress = 100;
  if (newState.title.isEmpty) {
    newState.title = action.payload.replaceAll('"', '');
  }
  return newState;
}

WebState _countUp(WebState state, Action action) {
  final WebState newState = state.clone()..progress = action.payload;
  return newState;
}
